/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans;

import EntityBeans.Client;
import EntityBeans.OrderProduct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Pierre
 */
@Stateless 
public class OrderProductFacade extends AbstractFacade<OrderProduct> implements OrderProductFacadeLocal {
    @PersistenceContext(unitName = "Apppstore-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public OrderProductFacade() {
        super(OrderProduct.class);
    }
    
    @Override
     public int findLastOrder(Client client)
     {
        Query query;
        query = em.createNamedQuery("OrderProduct.findLastId");
        query.setParameter("client", client); //Fait le lien avec la nameQuery dans OrderProdut -> remplace :client
        Integer tmp = (Integer)query.getSingleResult();
        return tmp.intValue();
     }
    @Override
    public OrderProduct findByID(int id)
     {
        Query query;
        query = em.createNamedQuery("OrderProduct.findById");
        query.setParameter("id", id);
        OrderProduct tmp = (OrderProduct)query.getSingleResult();
        return tmp;
     }
    
}
